/****************************************************
文件：BuildAssetBundle.cs
作者：UnitySir
邮箱：zouajck@foxmail.com
日期：2021/03/22 20:24:37
功能：Nothing
*****************************************************/

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;

#endif

namespace DSFramework
{
#if UNITY_EDITOR

    /// <summary>
    /// AssetBundle 打包工具
    /// </summary>
    public class BuildAssetBundle
    {

        /// <summary>
        /// 打包生成所有的AssetBundles（包）
        /// </summary>
        [MenuItem("AssetBundleTools/BuildAllAssetBundles")]
        public static void BuildAllAB()
        {
            // 打包AB输出路径
            string strABOutPAthDir = string.Empty;

            // 获取“StreamingAssets”文件夹路径（不一定这个文件夹，可自定义）            
            strABOutPAthDir = PathTools.GetABOutPath();

            // 判断文件夹是否存在，不存在则新建
            if (Directory.Exists(strABOutPAthDir) == false)
            {
                Directory.CreateDirectory(strABOutPAthDir);
            }

            // 打包生成AB包 (目标平台自动根据当前平台设置)

#if UNITY_STANDALONE_WIN
            BuildPipeline.BuildAssetBundles(strABOutPAthDir, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);

#elif UNITY_IPHONE
            BuildPipeline.BuildAssetBundles(strABOutPAthDir, BuildAssetBundleOptions.None, BuildTarget.iOS);
#elif UNITY_ANDROID
            BuildPipeline.BuildAssetBundles(strABOutPAthDir, BuildAssetBundleOptions.None, BuildTarget.Android);

#endif
        }
    }
#endif
}